package juc.concurrent.countdownlatch;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(2);

        Thread thread00 = new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("00运行了");
                countDownLatch.countDown();
                System.out.println(countDownLatch.getCount());
            }
        });
        thread00.start();

        Thread thread01 = new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("01运行了");
                countDownLatch.countDown();
                System.out.println(countDownLatch.getCount());
            }
        });
        thread01.start();

        Thread thread02 = new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("02运行了");
                countDownLatch.countDown();
                System.out.println(countDownLatch.getCount());
            }
        });
        thread02.start();

        countDownLatch.await();
        System.out.println("main end");
    }
}
